home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / RESTRICT.CMM < prev    next >
Text File  |  1993-04-05  |  2KB  |  57 lines

  1. // Restrict.cmm   Allow user to only enter commands from the list provided here.
  2.  
  3. Count = 0;
  4. Valid[Count++] = "dir"
  5. Valid[Count++] = "chkdsk"
  6. Valid[Count++] = "type"
  7. Valid[Count++] = "cd"
  8. Valid[Count++] = "set"
  9. Valid[Count++] = "IsItFri"
  10. Valid[Count++] = "DiskFree"
  11.  
  12.  
  13. main()
  14. {
  15.    while ( True ) {  // True is always true, and so this will loop forever
  16.       ShowAvailableCommands()
  17.       Command = GetCommand()
  18.       // check if this command is in our list
  19.       for ( i = 0; i < Count; i++ ) {
  20.          if ( !strcmpi(Command.Root,Valid[i]) )
  21.             break
  22.       }
  23.       if ( i < Count ) {
  24.          system(Command.Full)
  25.       } else {
  26.          // The command was not found
  27.          printf("\"%s\" is not an available command!\a\n",Command.Root)
  28.       }
  29.    }
  30. }
  31.  
  32. ShowAvailableCommands()
  33. {
  34.    printf("\nYour available commands are:\n")
  35.    for ( i = 0; i < Count; i++ )
  36.       printf("%s\t",Valid[i])
  37. }
  38.  
  39. GetCommand()   // Get command from user, return a structure with two elements
  40.                //  .Root   root name of the command entered
  41.                //  .Full   complete line of input as entered
  42. {
  43.    printf("\nWhaddya want? ")
  44.    input.Full = gets()
  45.    // now figure out what the root was, first copy all of input, then remove space from
  46.    // beginning, then go to first space character
  47.    strcpy(input.Root,input.Full)
  48.    // then remove andy whitespace from beginning of command
  49.    while( input.Root[0] != 0  &&  isspace(input.Root[0] ) )
  50.       input.Root++
  51.    // end this string at the first whitespace character
  52.    for ( c = input.Root; c[0] != 0  &&  !isspace(c[0]); c++ ) ;
  53.    c[0] = 0
  54.    return(input)
  55. }
  56.  
  57.